home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *
- * NSSDC/CDF Correct attribute scopes.
- *
- * Version 2.0, 4-Mar-92, ST Systems (STX)
- *
- * Modification history:
- *
- * V1.0 24-Apr-91, J Love Original version (for CDF V2.1).
- * V1.1 25-Jun-91, J Love Added QOP. Added PageInst.
- * V1.2 1-Aug-91, J Love TRUE/FALSE. Use 'Exit'/'ExitBAD'. Use
- * 'CDFlib'. Added 'log' qualifier.
- * V2.0 4-Mar-92, J Love Modified for IBM PC port.
- *
- ******************************************************************************
- *
- * This program corrects all of the assumed attribute scopes to the
- * corresponding definite scopes (ie...
- *
- * ASSUMED_GLOBAL_SCOPE ---> GLOBAL_SCOPE, and
- * ASSUMED_VARIABLE_SCOPE ---> VARIABLE_SCOPE)
- *
- * Assumed scopes are normally the result of a Version 1 CDF being converted
- * to a Version 2 CDF.
- *
- ******************************************************************************/
-
- #include "cdfdist.h"
- #include "cdfscope.h"
-
- /******************************************************************************
- * Global variables.
- ******************************************************************************/
-
- CDFid id;
- Boolean mLog;
-
- /******************************************************************************
- * Main.
- ******************************************************************************/
-
- #if defined(vms)
- main (argc, argv)
- #else
- void main (argc, argv)
- #endif
- int argc;
- char *argv[];
- {
- CDFstatus status;
- long scope;
- long Nattrs;
- long attrN;
- long VARcount = 0;
- long GBLcount = 0;
- char answer[2];
- long confirm;
- char CDFname[80];
- char attrName[CDF_ATTR_NAME_LEN];
-
- QOP *qop;
- long count;
-
- static char *validQuals[] = { "confirm", "noconfirm", "log", "nolog", NULL };
- static int optRequired[] = { FALSE, FALSE, FALSE, FALSE, 0 };
-
- static char *instructions[] = {
- #if defined(vms)
- "Usage: $ CDFSCOPE [/[no]CONFIRM] [/[no]LOG] <cdf-path>",
- #endif
- #if defined(unix)
- "Usage: % cdfscope [-[no]confirm] [-[no]log] <cdf-name>",
- #endif
- #if defined(__MSDOS__)
- "Usage: > cdfscope [-[no]confirm] [-[no]log] <cdf-name>",
- #endif
- "",
- "Purpose: CDFscope is used to correct the assumed scopes that may be",
- " found in a CDF. These assumed scopes are normally a result",
- " of converting a Version 1 CDF to a Version 2 CDF.",
- "",
- "Parameter(s): <cdf-path>",
- " The pathname of the CDF to be corrected (do not specify an",
- " extension).",
- "",
- #if defined(vms)
- "Qualifier(s): /[no]CONFIRM",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- "Qualifier(s): -[no]confirm",
- #endif
- " Specifies whether or not the program prompts for",
- " confirmation before correcting a scope. The valid",
- " responses to the confirmation prompts are as follows.",
- "",
- " Y/y Yes, correct the scope (assumed --> definite).",
- " N/n No, don't correct the scope.",
- " G/g Correct the scope to GLOBAL_SCOPE.",
- " V/v Correct the scope to VARIABLE_SCOPE.",
- "",
- " The default is to confirm all scopes without prompting for",
- " confirmation.",
- "",
- #if defined(vms)
- " /[no]LOG",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- " -[no]log",
- #endif
- " Specifies whether or not message logging is enabled.",
- " The default is message logging disabled.",
- "",
- #if defined(vms)
- "Example(s): $ CDFSCOPE TOGA_ECMWF",
- " $ CDFSCOPE/CONFIRM/NOLOG TOGA_ECMWF",
- #endif
- #if defined(unix)
- "Example(s): % cdfscope toga_ecmwf",
- " % cdfscope -confirm -nolog ../toga_ecmwf",
- #endif
- #if defined(__MSDOS__)
- "Example(s): > cdfscope ..\\toga",
- " > cdfscope -confirm -nolog a:\\cdfs\\toga",
- #endif
- NULL };
-
- /******************************************************************************
- * Get qualifiers/options/parameters.
- ******************************************************************************/
-
- switch (argc == 1) {
- case 1:
- PageInst (instructions);
- Exit;
- default:
- qop = Qop (argc, argv, validQuals, optRequired);
- if (qop == NULL) ExitBAD;
-
- if (qop->Nparms < 1) {
- printf ("Missing parameter.\n");
- ExitBAD;
- }
- else {
- strcpy (CDFname, qop->parms[0]);
- }
-
- count = 0;
- if (qop->qualEntered[0]) count++;
- if (qop->qualEntered[1]) count++;
-
- switch (count) {
- case 0:
- confirm = FALSE;
- break;
- case 1:
- if (qop->qualEntered[0])
- confirm = TRUE;
- else
- confirm = FALSE;
- break;
- default:
- printf ("Conflicting qualifiers.\n");
- ExitBAD;
- break;
- }
-
- count = 0;
- if (qop->qualEntered[2]) count++;
- if (qop->qualEntered[3]) count++;
-
- switch (count) {
- case 0:
- mLog = FALSE;
- break;
- case 1:
- if (qop->qualEntered[2])
- mLog = TRUE;
- else
- mLog = FALSE;
- break;
- case 2:
- printf ("Conflicting qualifiers.\n");
- ExitBAD;
- break;
- }
-
- break;
- }
-
- /******************************************************************************
- * Open CDF.
- ******************************************************************************/
-
- status = CDFlib (OPEN_, CDF_, CDFname, &id,
- GET_, CDF_NUMATTRS_, &Nattrs,
- NULL_);
- StatusHandler (status);
-
- /******************************************************************************
- * Correct the scope of each attribute (if necessary).
- ******************************************************************************/
-
- if (Nattrs == 0) {
- if (mLog) printf ("No attributes in CDF.\n");
- }
- else {
- for (attrN = 0; attrN < Nattrs; attrN++) {
- status = CDFlib (SELECT_, CDF_, id,
- ATTR_, attrN,
- GET_, ATTR_SCOPE_, &scope,
- ATTR_NAME_, attrName,
- NULL_);
- StatusHandler (status);
-
- switch (scope) {
- case VARIABLE_SCOPE_ASSUMED:
- if (confirm) {
- printf ("Attribute %s has ASSUMED VARIABLE scope, correct? ",
- attrName);
- printf ("[y/n/g/v] => ");
- scanf ("%s", answer);
- }
- else
- answer[0] = 'y';
-
- switch (answer[0]) {
- case 'y':
- case 'Y':
- status = CDFlib (SELECT_, CDF_, id,
- PUT_, ATTR_SCOPE_, VARIABLE_SCOPE,
- NULL_);
- StatusHandler (status);
- VARcount++;
- break;
- case 'n':
- case 'N':
- break;
- case 'g':
- case 'G':
- status = CDFlib (SELECT_, CDF_, id,
- PUT_, ATTR_SCOPE_, GLOBAL_SCOPE,
- NULL_);
- StatusHandler (status);
- GBLcount++;
- break;
- case 'v':
- case 'V':
- status = CDFlib (SELECT_, CDF_, id,
- PUT_, ATTR_SCOPE_, VARIABLE_SCOPE,
- NULL_);
- StatusHandler (status);
- VARcount++;
- break;
- }
- break;
-
- case GLOBAL_SCOPE_ASSUMED:
- if (confirm) {
- printf ("Attribute %s has ASSUMED GLOBAL scope, correct? ",
- attrName);
- printf ("[y/n/g/v] => ");
- scanf ("%s", answer);
- }
- else
- answer[0] = 'y';
-
- switch (answer[0]) {
- case 'y':
- case 'Y':
- status = CDFlib (SELECT_, CDF_, id,
- PUT_, ATTR_SCOPE_, GLOBAL_SCOPE,
- NULL_);
- StatusHandler (status);
- GBLcount++;
- break;
- case 'n':
- case 'N':
- break;
- case 'g':
- case 'G':
- status = CDFlib (SELECT_, CDF_, id,
- PUT_, ATTR_SCOPE_, GLOBAL_SCOPE,
- NULL_);
- StatusHandler (status);
- GBLcount++;
- break;
- case 'v':
- case 'V':
- status = CDFlib (SELECT_, CDF_, id,
- PUT_, ATTR_SCOPE_, VARIABLE_SCOPE,
- NULL_);
- StatusHandler (status);
- VARcount++;
- break;
- }
- break;
- }
- }
-
- if (mLog) {
- if (GBLcount == 0 && VARcount == 0)
- printf ("No assumed scopes corrected and/or found.\n");
- else {
- printf ("%ld scope%s corrected to GLOBAL, ",
- GBLcount, (GBLcount == 1 ? "" : "s"));
- printf ("%ld scope%s corrected to VARIABLE.\n",
- VARcount, (VARcount == 1 ? "" : "s"));
- }
- }
- }
-
- /******************************************************************************
- * Close CDF and exit;
- ******************************************************************************/
-
- status = CDFlib (SELECT_, CDF_, id,
- CLOSE_, CDF_,
- NULL_);
- StatusHandler (status);
-
- Exit;
- }
-
-
- /******************************************************************************
- * StatusHandler.
- ******************************************************************************/
-
- void StatusHandler (status)
- CDFstatus status;
- {
- char text[CDF_STATUSTEXT_LEN + 1];
-
- if (status == CDF_OK) return; /* Do nothing. */
-
- CDFlib (SELECT_, CDF_STATUS_, status,
- GET_, STATUS_TEXT_, text,
- NULL_);
-
- if (status < CDF_WARN) {
- printf ("ERROR> %s\n", text);
- CDFlib (SELECT_, CDF_, id,
- CLOSE_, CDF_, id,
- NULL_);
- ExitBAD;
- }
- else
- if (mLog)
- if (status < CDF_OK)
- printf ("WARNING> %s\n", text);
- else
- printf ("INFO> %s\n", text);
-
- return;
- }
-